import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;

public class SorterParent<Type extends Comparable<Type>> implements Sorter<Type> {
	protected long steps;
	protected long endTime = 0;
	protected BufferedWriter writer;
	protected ArrayList<String> log = new ArrayList<String>();
	protected String method;
	protected long startTime;

	@Override
	public Type[] sort(Type[] toSort, String method) {
		startTime = System.nanoTime();
		this.method = method;
		steps = 0;
		log.add("Start of log. Nanotime is: " + startTime + "\n");
		return null;
	}

	@Override
	public void writeStats(Type[] result, String sortType) {
		try {
			writer = new BufferedWriter(new FileWriter(sortType + "Log" + method +".txt"));
			writer.write("====================== \n");
			writer.write("Method used: \n");
			writer.write("  " + method + "list sorting using " + sortType + "Sort \n");
			writer.write("====================== \n");
			writer.write("Size of list: \n");
			writer.write("  " + result.length + "\n");
			writer.write("====================== \n");
			writer.write("Time elapsed: \n");
			writer.write("  " + (endTime - startTime) + " nanoseconds. \n");
			writer.write("  " + ((endTime - startTime) / 1000000000.0)
					+ " seconds. \n");
			writer.write("Steps taken: \n");
			writer.write("  " + steps + "\n");
			writer.write("====================== \n");
			writer.write("Result: \n");
			for (int i = 0; i < result.length; i++) {
				writer.write(result[i] + "\n");
			}
			writer.write("====================== \n");
			writer.write("Thanks for watching folks! \n");

			for (String entry : log) {
				writer.write(entry);
			}

			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
